package tk.mybatis.springboot.service;

import java.util.List;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;
public class LogicalCondition<E> {

    public Example LogicalParam(E e,List< LogicalParam> param){
        Example example = new Example(e.getClass());
        Criteria criteria=example.createCriteria(); 
        if(param==null)return example;
        for(LogicalParam  q : param){
            String key=q.getKey();
            String property=q.getValue();
            String opration=q.getOperation();
            String orAnd=q.getOrAnd(); 
           if(opration.equals("eq")){
                if(orAnd.equals("and"))
                        criteria.andEqualTo(key, property);
                else if(orAnd.equals("or"))
                        criteria.orEqualTo(q.getKey(), property);
            

           }else if(opration.equals("le")){
            if(orAnd.equals("and"))
                criteria.andLessThan(key, property);
            else
                criteria.orLessThan(key, property);
            
           }else if(opration.equals("ge")){
            if(orAnd.equals("and"))
                    criteria.andGreaterThan(key, property);
             else
                    criteria.orGreaterThan(key, property);
           }
        }
        example.and(criteria);
        return example;

    }


}
